package pokerclient.ctrl;

import common.GameAction;

import pokerclient.core.ClientModel;
import pokerserver.core.ServerModel;

/**
 * Controller class. Takes requests from mostly the view and delegates them to
 * appropriate classes.
 * 
 * @author M�rten
 * 
 */
public class ClientController {

	/**
	 * Class variables
	 */
	private static ClientController controller;
	private ClientModel model;

	/**
	 * Private constructor
	 */
	private ClientController() {
		this.model = ClientModel.getInstance();
	}

	/**
	 * Singleton getter
	 * 
	 * @return the instance of the controller
	 */
	public static ClientController getInstance() {
		if (controller == null) {
			controller = new ClientController();
		}
		return controller;
	}

	/*
	 * Process and forward actions sent from the view (below) (ex: fold, check,
	 * call, etc.)
	 */

	public void hostButtonPressed() {
		pokerserver.core.ServerModel.getInstance(); // initialize the server
		ServerModel.startNetwork(); // start the network (listener)
	}

	public void startGameButtonPressed() {
		// We don't need to care about checking if the local player is the host,
		// that will be done on the server regardless.
		model.requestStartGame();
	}

	public void connectButtonPressed(String playerName, String host) {
		// Send the text field string to the model, telling it you wish to
		// connect:
		model.connect(playerName, host);
	}

	public void foldButtonPressed() {
		model.announcePlayerAction(GameAction.FOLD, 0);
	}

	public void betButtonPressed(int bet) {
		model.announcePlayerAction(GameAction.BET, bet);
	}

	public void allinButtonPressed() {
		model.announcePlayerAction(GameAction.ALL_IN, 0);
	}

	public void checkButtonPressed() {
		model.announcePlayerAction(GameAction.CHECK, 0);
	}

	public void callButtonPressed() {
		model.announcePlayerAction(GameAction.CALL, 0);
	}

}
